package com.yiyefanchen.ai.controller;

import com.yiyefanchen.ai.utils.SseEmitterUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequestMapping("/sse")
public class SseController {

    @GetMapping("/connect/{chatId}")
    public SseEmitter connect(@PathVariable("chatId") String chatId) {
        return SseEmitterUtil.createSse(chatId);
    }

    @GetMapping("/close/{chatId}")
    public void close(@PathVariable("chatId") String chatId) {
    	SseEmitterUtil.removeSse(chatId);
    }
}